<?php
session_start(); 
//error_reporting(7);
require_once '../../includes/global.php';
require_once '../rizhi.php';
//Jc('g');
//配xajax

function updatetag($name,$did)
{		$objResponse = new xajaxResponse();
		$objResponse->sEncoding="utf-8";
		$_SESSION[$did]=$name;
	    $objResponse->addAssign('loading',"innerHTML","");
		return $objResponse;
}
	
$xajax = new xajax(); 
$xajax->bDecodeUTF8Input=true;

$xajax->registerFunction("updatetag");
$xajax->processRequests();
//得到配置文件
$wcfg=Dga('wcfg',"web like '".$sitename."' and lg like '".$_SESSION[LG]."'");
$wcfg=json_decode($wcfg[wcfg],true);
$dcfg=Dga('dcfg',"id like '".$_GET[did]."'");
$dcfg=json_decode($dcfg[dcfg],true);
$_SESSION[$dcfg['name']]==''&&$_SESSION[$dcfg['name']]='1';
$xuan=array();$yin=array();$search=array();
$condition=array();
foreach($dcfg[structure] as $dkey =>$dvalue){
	//yinxuan
	switch ($dvalue['show']){
				case 1:{
				$xuan[$dkey]=$dvalue['COMMENT'];
				 break;
				}
				case 2:{
				$yin[$dkey]=$dvalue['COMMENT'];
				 break;
				}
				default :{
				 break;
				}
		}	
	//search
	switch ($dvalue['search']){
				case 1:{
				$search[$dkey]=$dvalue['COMMENT'];
					$_GET[$_GET['lg']][$dkey]!=''&&$condition[$_GET['lg']].=" and ".$dkey." like '".$_GET[$_GET[lg]][$dkey]."' ";
				 break;
				}
				case 2:{
				$search[$dkey]=$dvalue['COMMENT'];
				$_GET[$_GET[lg]]!=''&&$condition[$_GET['lg']].=" and ".$dkey." like '%".$_GET[$_GET[lg]][$dkey]."%' ";
				 break;
				}
				case 3:{
				$search[$dkey]=$dvalue['COMMENT'];
				sort($_GET[$_GET[lg]][$dkey]);
				$tseslec=implode(',',$_GET[$_GET[lg]][$dkey]);
				//Jc($_GET[$_GET[lg]][$dkey]);
				$tseslec!=''&&$tseslec!='0'&&$condition[$_GET['lg']].=" and INSTR(".$dkey.",',".$tseslec.",')>0  ";
				 break;
				}
				default :{
				 break;
				}
		}	
	//附加功能
	if($dvalue['ftype']=='bind'){
			$bind[$dkey]=$dvalue['COMMENT'];
				}
	//推荐属性
	if($dvalue['ftype']=='recommend'){
			$recommend[$dkey]=$dvalue['COMMENT'];
				}
	//分类式信息浏览
	if($dvalue['ftype']=='dselect'){
			$fen=true;
				}

	//浏览数值需要转换
	switch ($dvalue['change']){
				case 'yinyong':{
				$yinyong[]=$dkey;
				 break;
				}
				case 2:{
				$search[$dkey]=$dvalue['COMMENT'];
				$_GET[$_GET[lg]]!=''&&$condition[$_GET['lg']].=" and ".$dkey." like '%".$_GET[$_GET[lg]][$dkey]."%' ";
				 break;
				}
				default :{
				 break;
				}
		}	

	}

//Jc($dcfg);
//检测多语言屏蔽
if(array_key_exists($dcfg['name'],$wcfg['ping'])){
	$wcfg['num']=1;
	$temp=$wcfg['lang'][$wcfg['ping'][$dcfg['name']]];
	unset($wcfg['lang']);
	$wcfg['lang'][$wcfg['ping'][$dcfg['name']]]=$temp;
}
//Jc($wcfg);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <?php
        $xajax->printJavascript('/includes/class/xajax/');
    ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Prosperous JIMU</title>
<link  href="../css/mod.css"  rel="stylesheet" type="text/css" />
<!--<script type="text/javascript">parent.document.getElementById('loading').innerHTML = '正在加载UI组建...';</script>
!-->
<script   language="javascript">   
                  if   (top.location   ==   self.location)   
                      alert('此路不通');
					  window.close();
              </script>

<script language="javascript">

function switchTag(tag,content){
var allnum=<?php echo $wcfg[num];?>;
	for(i=1; i <=allnum+1; i++)
	{
		if ("tag"+i==tag)
		{
			document.getElementById(tag).getElementsByTagName("a")[0].className="selectli"+i;
			document.getElementById(tag).getElementsByTagName("a")[0].getElementsByTagName("span")[0].className="selectspan"+i;
			uptag(i);
		}else{
			document.getElementById("tag"+i).getElementsByTagName("a")[0].className="";
			document.getElementById("tag"+i).getElementsByTagName("a")[0].getElementsByTagName("span")[0].className="";
		}
		if ("content"+i==content)
		{
			document.getElementById(content).className="";
		}else{
			document.getElementById("content"+i).className="hidecontent";
		}
		document.getElementById("content").className=content;
	}
}

</script>

</head>
<body>

<div id="container">
<div id="title">
    <ul>
<?php $i=1;
	    foreach($wcfg[lang] as $key =>$lg){
		         if($i==1){
				 $temp1="class=\"selectli".$i."\"";
				 $temp2="class=\"selectspan".$i."\"";
				 }else{
				 $temp1="";
				 $temp2="";
				 }
				
		echo "<li id=\"tag".$i."\"><a href=\"#\" onclick=\"switchTag('tag".$i."','content".$i."');this.blur();\" ".$temp1."><span ".$temp2.">".$dcfg['title']."【".$lg."】</span></a></li>";
		$i++;
		}
?>
    </ul>
  </div>
  <div id="content" class="content1">
    <div id="loading"></div>

<?php
$xhgs=1;
 foreach($wcfg[lang] as $lgk =>$lgv){
		 if($xhgs==1){
		 echo " <div id=\"content".$xhgs."\" >";
				 }else{
				 echo "<div id=\"content".$xhgs."\" class=\"hidecontent\">";
				 }
				
		echo "<fieldset><legend>><img src='../img/find.gif' border='0'  style='display:left;vertical-align:middle;' ait='检索'> ".$dcfg[title]."检索〖SEARCH〗</legend>";
		//内容开始
		?>
        <form action="l.php" method="get" enctype="multipart/form-data"  id="vform">
     <?php
		 //Jc('g');
 
	 foreach($search as $key => $value){
	 $dcfg['structure'][$key]['ftype']($key,$lgk,0,0);
		 echo ":";
	 $dcfg['structure'][$key]['ftype']($key,$lgk,1,0,$_GET[$lgk][$key]);
	 }
	 ?>
     <input type="hidden" value="<?php echo $_GET['did'];?>" name='did'/>
     <input type="hidden" value="<?php echo $_GET['bdb'];?>" name='bdb'/>
     <input type="hidden" value="<?php echo $_GET['bdid'];?>" name='bdid'/>
     <input type="hidden" value="<?php echo $lgk;?>" name='lg'/>
     <input name="SEARCH"  value="检索" type="submit" /></form>
		<br />	<br />
        </fieldset>

		<br />
	<?php
	if($fen==true){
	$fen="<a href='sort.php?did=".$_GET['did']."'  title='分类目录式浏览【LIST】'><img src='../img/list.gif' border='0' ait='分类目录式浏览【LIST】'></a>";
	}
	
    echo  $fen.(($_GET['bdb'])?(" <a href='c.php?did=".$_GET['bdb']."' title='添加父类信息【AddParent】'><img src='../img/folder_new.gif' border='0' ait='添加父类信息【AddParent】'></a> <a href='l.php?did=".$_GET['bdb']."' title='列表父类信息【ListParent】'><img src='../img/note.gif' border='0' ait='列表父类信息【ListParent】'></a>"):(""))."       <a href='c.php?did=".$_GET['did'].(($_GET['bdb'])?("&bdb=".$_GET['bdb']."&bdid=".$_GET['bdid'].""):(""))."' title='添加【ADD】'><img src='../img/add.gif' border='0' ait='添加【ADD】'></a>   <a href='#' onclick=\"location.reload();\" title='刷新【REFRESH】'><img src='../img/page_refresh.gif' border='0' ait='刷新【REFRESH】'></a>  <a href='javascript:history.go(-1)'  title='后退【BACK】'><img src='../img/arrow_rotate_anticlockwise.png' border='0' ait='后退【BACK】'></a>";
	?>	
      <table width="100%" border="1" align="center" cellpadding="0" cellspacing="0"  bordercolor="#999999"  style="border-collapse: collapse">
		<tr> 
        </tr>
        <!-- 表头 !-->
        <tr></tr>

        <tr>  
		<?php
		foreach($xuan as $key => $value){
		echo "<td height='30' align='center'>".$value."</td>";
		}
		?>
        <td height='30' align='center'>操作〖OPERATE〗</td>
		</tr>
        <?php
!$_REQUEST[page]&&$_GET[page]=1;
$_REQUEST[page]&&$_GET[page]=$_REQUEST[page];
//配置搜索
$pageline=$dcfg['pageline'];
//$pageline=1;
!$_GET['del']&&$_GET['del']=1;
$_GET['bdb']&&$condition[$lgk].=" and bdb like '".$_GET['bdb']."'  ";
$_GET['bdid']&&$condition[$lgk].=" and bdid = '".$_GET['bdid']."'  ";

$sql="SELECT count(id) as num
FROM ".$wcfg['prefix']."_".$dcfg['name']." AS A

where 1   and A.del!='".$_GET[del]."' and A.lg='".$lgk."' ".$condition[$lgk]."   ";
//echo $sql;
$res=mysql_query($sql);
$temp=mysql_fetch_array($res);
//$ttt->assign('znum',$temp[num]);
$ajaxpage=new lm_page(array('total'=>$temp[num],'perpage'=>$pageline,'page_name'=>'page'.$lgk));
mysql_free_result($res);
if($_GET['page'.$lgk]==''){
$_GET['page'.$lgk]=1;
}

$sql=" 
SELECT *
FROM ".$wcfg['prefix']."_".$dcfg['name']." AS A
where 1   and A.del!='".$_GET[del]."' and A.lg='".$lgk."' ".$condition[$lgk]."    LIMIT ".($_GET['page'.$lgk]-1)*$pageline." , ".$pageline." ";
echo $sql;
//数据
mysql_query("Set Names '".DEFAULT_CHARSET."' ");
	$result=mysql_query($sql);
	while($temp=mysql_fetch_array($result))
	{
		//Jc($temp);
		echo " <tr>  ";
		foreach($xuan as $key => $value){
			if(in_array($key,$yinyong)){
		echo "<td height='30' align='center'>".(yinyong($key,1,$temp[$key]))."</td>";
		}else{
		echo "<td height='30' align='center'>".$temp[$key]."</td>";
			}
		
		}
		//权限
		
		//推荐
		$tujian='';
			foreach($recommend as $rkey =>$rvalue){
				$tujian.=($temp[$rkey])?("<a  href='t.php?op=tui&did=".$dcfg['name']."&id=".$temp[id]."&zd=".$rkey."&v=0'  title='真〖".$rvalue."〗'><img src='../img/flag_".$dcfg['structure'][$rkey]['flag'].".gif' border='0' ait='真〖".$rvalue."〗'></a>"):("<a  href='t.php?op=xiao&did=".$dcfg['name']."&id=".$temp[id]."&zd=".$rkey."&v=1'  title='假〖".$rvalue."〗'><img src='../img/flag_white.gif' border='0' ait='假〖".$rvalue."〗'></a>");
			}
		echo "<td height='30' align='center'>
		
		<a href='c.php?did=".$_GET['did']."&gid=".$temp['gid']."' title='编辑〖EDIT〗'><img src='../img/edit.gif' border='0' ait='编辑〖EDIT〗'></a>
		<a href='d.php?did=".$_GET['did']."&id=".$temp['id']."' onclick=\"return confirm('你确定要删除？删除后将无法恢复！')\" title='删除〖DELETE〗'><img src='../img/delete.gif' border='0' ait='删除〖DELETE〗'></a>
		<a href='s.php?did=".$_GET['did']."&gid=".$temp['gid']."' title='浏览〖LIST〗 title='查看【SHOW】'><img src='../img/page_html.gif' border='0' ait='查看【SHOW】'></a>
		".(($bind)?("<a  href='#' onClick=\"showorhidden(p".$temp[id].")\" title='扩展〖EXTENSIONS〗'><img src='../img/list_extensions.gif' border='0' ait='扩展〖EXTENSIONS〗'></a>"):("")).$tujian."
		</td>";
		echo "</tr>";
		
		if($bind){
		echo "<tbody name='q".$temp[id]."' id='p".$temp[id]."' style=\"display:none;\">
  <tr><td height='20' colspan=16 bgColor=#ffffff align='right'>
	<div  style=\"margin-right:20px;\">";
	foreach($bind as $bkey => $bvalue){
echo $bvalue."【<a href='c.php?did=".$dcfg['structure'][$bkey]['did']."&bdb=".$_GET['did']."&bdid=".$temp['gid']."&comment=".urlencode($bvalue['COMMENT'])."' title='添加".$dvalue['COMMENT']."【AddBind】'><img src='../img/image_new.gif' border='0' ait='添加".$dvalue."【AddBind】'></a> <a href='l.php?did=".$dvalue['did']."&bdb=".$_GET['did']."&bdid=".$_GET['gid']."&comment=".urlencode($dvalue['COMMENT'])."' title='列表".$dvalue['COMMENT']."【Listbind】'><img src='../img/image.gif' border='0' ait='列表".$dvalue['COMMENT']."【Listbind】'></a>  】";
	}
	echo "</div>
 </td></tr></tbody>	
		";
		}
	}
mysql_free_result($result);

		?>
		</table>
    <div  align="center">
    <fieldset><legend>分页浏览</legend>
   <?php echo $ajaxpage->show(1);?> </fieldset>
    </div>

		<?php
		$xhgs++;
		echo "</div>";
		}
	?>
        </div>

</body>
<script language="javascript">
function uptag(tagid)
{
document.getElementById('loading').innerHTML="<table><tr nowrap=\"nowrap\" class=\"firstalt\"><td colspan=2><img src=\"/includes/sysimg/loading.gif\"/></td></tr></table>";
xajax_updatetag(tagid,'<?php echo $dcfg['name'];?>');
}
switchTag('tag<?php echo $_SESSION[$dcfg['name']];?>','content<?php echo $_SESSION[$dcfg['name']];?>');
function showorhidden(nodeObject){
      if (nodeObject.style.display == '' || nodeObject.style.display == 
'block') {
        nodeObject.style.display = 'none';
      } else {
        nodeObject.style.display = 'block';
      }
    }
</script>
</html>